package com.ruoyi.merchant.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.geo.Distance;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class RescueOrderWebSocket {

    @Autowired
    private SimpMessagingTemplate messagingTemplate;

    /**
     * 通知商户有新的救援订单
     */
    public void notifyMerchant(Long merchantId, Long orderId, Distance distance) {
        Map<String, Object> message = new HashMap<>();
        message.put("orderId", orderId);
        message.put("distance", String.format("%.2fkm", distance.getValue()));
        message.put("timestamp", System.currentTimeMillis());

        // 推送到商户专属频道
        messagingTemplate.convertAndSendToUser(
                merchantId.toString(),
                "/queue/rescue-orders",
                message
        );
    }
}
